package com.demo.TDengine.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.pagination.dialects.PostgreDialect;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

/**
 * @author qkj
 */
@Configuration
public class MybatisPlusConfig {

    @Primary
    @Bean
    public MybatisPlusInterceptor paginationInterceptor() {
        // mybatis plus 旧版本
 //        PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
//        //TODO: mybatis-plus do not support TDengine, use postgresql Dialect
//        paginationInterceptor.setDialectType("postgresql");

        // mybatis plus 新版本写法
        MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();
        PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor();
        paginationInnerInterceptor.setDbType(DbType.POSTGRE_SQL);
        paginationInnerInterceptor.setDialect(new PostgreDialect());
        mybatisPlusInterceptor.addInnerInterceptor(paginationInnerInterceptor);

        return mybatisPlusInterceptor;
    }

}
